procedure TFrmDlg.DMerchantDlgShowText(Sender: TObject; dsurface:
  TDXTexture; Msg, SelectStr: string; X, Y: Word;
  Points: TList; var AddPoints: Boolean);
var
  str, data, fdata, cmdstr, cmdmsg, cmdparam: string;
  lx, ly, sx: integer;
  drawcenter: Boolean;
  pcp: PTClickPoint;
  boColor: Boolean;
  Color: TColor;
  sColor, sTemp: string;
  Idx: Integer;
    FontColor: TColor;

  function ColorText(sStr: string; DefColor: TColor; boDef, boLength: Boolean):
      string;
  var
    sdata, sfdata, scmdstr, scmdparam, scmdcolor: string;
  begin
    Result := '';
    sdata := sStr;
   with g_DXCanvas do begin
    with Sender as TDWindow do
    begin
      while (pos('{', sdata) > 0) and (pos('}', sdata) > 0) and (sdata <> '') do
      begin
        if sdata[1] <> '{' then
        begin
          sdata := '{' + GetValidStr3(sdata, sfdata, ['{']);
        end;
        sdata := ArrestStringEx(sdata, '{', '}', scmdstr);
        if scmdstr <> '' then
        begin
          scmdparam := GetValidStr3(scmdstr, scmdstr, ['=']);
          scmdcolor := GetValidStr3(scmdparam, scmdparam, ['=']);
        end;
        if sfdata <> '' then
        begin
          if boLength then
          begin
            Result := Result + sfdata;
          end
          else
          begin
            //ֺһ֮
            TextOut( SurfaceX(Left + lx + sx), SurfaceY(Top + ly),
              DefColor,  sfdata);
            sx := sx + TextWidth(sfdata);
          end;
        end;
        Color := DefColor;
        if CompareText(scmdparam, 'FCOLOR') = 0 then
        begin
          Color := GetRGB(Lobyte(Str_ToInt(scmdcolor, 255)));
        end
        else if CompareText(scmdparam, 'AUTOCOLOR') = 0 then
        begin
          NpcTempList.Clear;
          if ExtractStrings([','], [], PChar(scmdcolor), NpcTempList) > 0 then
          begin
            Idx := AutoColorIdx mod NpcTempList.Count;
            scmdcolor := NpcTempList.Strings[Idx];
          end;
          Color := GetRGB(Lobyte(Str_ToInt(scmdcolor, 255)));
        end;
        if boDef then
          Color := DefColor;
        if boLength then
        begin
          Result := Result + scmdstr;
        end
        else
        begin//ɫĶ»
         // TextOut( SurfaceX(Left + lx + sx), SurfaceY(Top + ly),
         //   Color, scmdstr);
          g_NEWFont.TextOut(Left+lx+sx,top+ly,Color,scmdstr,True);
          sx := sx + TextWidth(scmdstr);
        end;
      end; //end while
      if sdata <> '' then
      begin  //Ǻɫͻɫͻ»
       if (DefColor= clYellow) or (DefColor= clRed) then begin
         g_NEWFont.TextOut(Left+lx+sx,top+ly,DefColor,sdata,True);
       end;

        if boLength then
        begin
          Result := Result + sdata;
        end
        else
        begin
          TextOut( SurfaceX(Left + lx + sx), SurfaceY(Top + ly),
            DefColor,  sdata);
          sx := sx + TextWidth(sdata);
        end;
       //end;
        end;
      end;
    end;
  end;

begin
  try //Զ
    with Sender as TDWindow do
    begin
          with g_DXCanvas do begin
      lx := x;
      ly := y;
      str := Msg;
      drawcenter := FALSE;
      while TRUE do
      begin
        if str = '' then
          break;
        str := GetValidStr3(str, data, ['\']);
        if data <> '' then
        begin
          sx := 0;
          fdata := '';
          while (pos('<', data) > 0) and (pos('>', data) > 0) and (data <> '')
            do
          begin
            if data[1] <> '<' then
            begin
              data := '<' + GetValidStr3(data, fdata, ['<']);
            end;
            data := ArrestStringEx(data, '<', '>', cmdstr);

            //fdata + cmdstr + data
            if cmdstr <> '' then
            begin
              if Uppercase(cmdstr) = 'C' then
              begin
                drawcenter := TRUE;
                continue;
              end;
              if UpperCase(cmdstr) = '/C' then
              begin
                drawcenter := FALSE;
                continue;
              end;
              cmdparam := GetValidStr3(cmdstr, cmdstr, ['/']);
              //cmdparam : Ŭ Ǿ  
            end
            else
            begin
              DMenuDlg.Visible := FALSE;
              DSellDlg.Visible := FALSE;
            end;

            if fdata <> '' then
            begin
              ColorText(fdata, clwhite, False, False);
              {if fdata<>'' then begin
                BoldTextOut (dsurface, SurfaceX(Left+lx+sx), SurfaceY(Top+ly), clWhite, clBlack, fdata);
                sx := sx + dsurface.Canvas.TextWidth(fdata);
              end;}
            end;
            if cmdstr <> '' then
            begin
              boColor := False;
              if CompareLStr(cmdparam, 'FCOLOR', length('FCOLOR')) then
              begin
                boColor := True;
                sColor := GetValidStr3(cmdparam, sTemp, ['=']);
                Color := GetRGB(Lobyte(Str_ToInt(sColor, 255)));
                //DScreen.AddChatBoardString (sColor, GetRGB(255), GetRGB(0));
              end
              else if CompareLStr(cmdparam, 'AUTOCOLOR', length('AUTOCOLOR'))
                then
              begin
                boColor := True;
                sColor := GetValidStr3(cmdparam, sTemp, ['=']);
                NpcTempList.Clear;
                if ExtractStrings([','], [], PChar(sColor), NpcTempList) > 0
                  then
                begin
                  Idx := AutoColorIdx mod NpcTempList.Count;
                  sColor := NpcTempList.Strings[Idx];
                end;
                Color := GetRGB(Lobyte(Str_ToInt(sColor, 255)));
              end;
              if boColor then
              begin
                TextOut(SurfaceX(Left + lx + sx), SurfaceY(Top +
                  ly), Color,  cmdstr); 
                sx := sx + TextWidth(cmdstr);
              end
              else
              begin
                if (AddPoints) and (cmdparam <> '') then
                begin
                  new(pcp);
                  pcp.rc := Rect(lx + sx, ly, lx + sx +
                    TextWidth(ColorText(cmdstr, clRed, False,
                    True)), ly + 14);
                  pcp.RStr := cmdparam;
                  Points.Add(pcp);
                end;
                if cmdparam = '' then
                begin
                  ColorText(cmdstr, clRed, False, False); 
                end
                else
                begin
                 // dsurface.Canvas.Font.Style := dsurface.Canvas.Font.Style +
                   // [fsUnderline];
                  if SelectStr = cmdparam then
                    ColorText(cmdstr, clRed, True, False)
                      //BoldTextOut (dsurface, SurfaceX(Left+lx+sx), SurfaceY(Top+ly), clRed, clBlack, cmdstr)
                  else
                    ColorText(cmdstr, clYellow, False, False);

                end;

              end;
            end;
          end;
          if data <> '' then
            ColorText(data, clwhite, False, False);
          //BoldTextOut (dsurface, SurfaceX(Left+lx+sx), SurfaceY(Top+ly), clWhite, clBlack, data);
        end;
        ly := ly + 16;
      end;

      AddPoints := FALSE;
    end;
    if (GetTickCount - AutoTick) > 500 then
    begin
      AutoTick := GetTickCount;
      Inc(AutoColorIdx); //Զɫ
    end;
    end;
  except //Զ
    DebugOutStr('[Exception] TFrmDlg.DMerchantDlgDirectPaint');
    //Զ
  end; //Զ
  //
end;